//
//  UILayer.m
//  cocos2dFirstTest
//
//  Created by Daniel Alexander on 7/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "UILayer.h"


@implementation UILayer

-(id)initWithPlayingScreen:(PlayingScreen *)screen {
    if( (self=[super init])) {
    
        playingScreen = screen;
        
        CCSprite *moveBtnBack = [CCSprite spriteWithFile:@"btn_back.png"];
        moveBtnBack.position = ccp(60,60);
        [self addChild:moveBtnBack];
        
        // up movement button
        CCMenuItem *btnMoveUp = [CCMenuItemImage itemFromNormalImage:@"btn_up.png" selectedImage:@"btn_up.png" target:self selector:@selector(upButtonTapped:)];
        btnMoveUp.position = ccp(60, 86);
        
        CCMenuItem *btnMoveDown = [CCMenuItemImage itemFromNormalImage:@"btn_up.png" selectedImage:@"btn_up.png" target:self selector:@selector(downButtonTapped:)];
        btnMoveDown.position = ccp(60,30);
        
        CCMenuItem *btnMoveLeft = [CCMenuItemImage itemFromNormalImage:@"btn_left.png" selectedImage:@"btn_left.png" target:self selector:@selector(leftButtonTapped:)];
        btnMoveLeft.position = ccp(32,58);
        
        CCMenuItem *btnMoveRight = [CCMenuItemImage itemFromNormalImage:@"btn_left.png" selectedImage:@"btn_left.png" target:self selector:@selector(rightButtonTapped:)];
        btnMoveRight.position = ccp(88,58);
        
        //movement button menu
        CCMenu *moveMenu = [CCMenu menuWithItems:btnMoveUp,btnMoveDown,btnMoveLeft,btnMoveRight, nil];
        moveMenu.position = CGPointZero;
        [self addChild:moveMenu];
        
    }
    return self;
}

- (void)upButtonTapped:(id)sender {
    NSLog(@"move up button pushed");
    [playingScreen MovePlayer:0 y:-1];
}

-(void)downButtonTapped:(id)sender{
    NSLog(@"move down button pushed");
    [playingScreen MovePlayer:0 y:1];
}

-(void)leftButtonTapped:(id)sender{
    NSLog(@"move left button pushed");
    [playingScreen MovePlayer:-1 y:0];
}

-(void)rightButtonTapped:(id)sender{
    NSLog(@"move right button pushed");
    [playingScreen MovePlayer:1 y:0];
}

@end
